import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDItem {
	/**ID*/
	id,
	/**优先级，用于排序*/
	order,
	/**名称*/
	name,
	/**描述*/
	desc,
	/**颜色1白2绿3蓝4紫5橙6红*/
	color,
	/**图标*/
	icon,
	/**使用类型：1.资源点2.道具3.装备4.符文5.魔纹*/
	itemType,
	/**道具使用等级*/
	useLevel,
	/**使用类型--1消耗品2随机宝箱3选择宝箱*/
	useType,
	/**使用参数1--type1*/
	useValue_1,
	/**使用参数2--type2*/
	useValue_2,
	/**按钮类型*/
	btnType,
	/**最大叠加数*/
	maxCount,
	/**出售类型时itemid*/
	saleType,
	/**出售价格(铜钱)---1不可出售*/
	saleNum,
	/**所有背包类型标签，用于标签筛选 --0：不显示在背包1：道具2：装备3：魔纹4：符文*/
	bagType,
	/**使用跳转*/
	useJumpID,
	/**获取途径*/
	gainWay,
	/**分解类型--1.晶石*/
	resolveType,
	/**是否稀有--1稀有*/
	rare,
	/**等级*/
	level,
	/**图鉴id*/
	handBookId,

	/**枚举数量*/
	EnumCount
}



export class CDItem{
	/**ID*/
	public id: number;
	/**优先级，用于排序*/
	public order: number;
	/**名称*/
	public name: number;
	/**描述*/
	public desc: number;
	/**颜色1白2绿3蓝4紫5橙6红*/
	public color: number;
	/**图标*/
	public icon: string;
	/**使用类型：1.资源点2.道具3.装备4.符文5.魔纹*/
	public itemType: number;
	/**道具使用等级*/
	public useLevel: number;
	/**使用类型--1消耗品2随机宝箱3选择宝箱*/
	public useType: number;
	/**使用参数1--type1*/
	public useValue_1: number;
	/**使用参数2--type2*/
	public useValue_2: number;
	/**按钮类型*/
	public btnType: number;
	/**最大叠加数*/
	public maxCount: number;
	/**出售类型时itemid*/
	public saleType: number;
	/**出售价格(铜钱)---1不可出售*/
	public saleNum: number;
	/**所有背包类型标签，用于标签筛选 --0：不显示在背包1：道具2：装备3：魔纹4：符文*/
	public bagType: number;
	/**使用跳转*/
	public useJumpID: number;
	/**获取途径*/
	public gainWay: number[];
	/**分解类型--1.晶石*/
	public resolveType: number;
	/**是否稀有--1稀有*/
	public rare: number;
	/**等级*/
	public level: number;
	/**图鉴id*/
	public handBookId: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDItem.id: return this.id;
			case E_CDItem.order: return this.order;
			case E_CDItem.name: return this.name;
			case E_CDItem.desc: return this.desc;
			case E_CDItem.color: return this.color;
			case E_CDItem.icon: return this.icon;
			case E_CDItem.itemType: return this.itemType;
			case E_CDItem.useLevel: return this.useLevel;
			case E_CDItem.useType: return this.useType;
			case E_CDItem.useValue_1: return this.useValue_1;
			case E_CDItem.useValue_2: return this.useValue_2;
			case E_CDItem.btnType: return this.btnType;
			case E_CDItem.maxCount: return this.maxCount;
			case E_CDItem.saleType: return this.saleType;
			case E_CDItem.saleNum: return this.saleNum;
			case E_CDItem.bagType: return this.bagType;
			case E_CDItem.useJumpID: return this.useJumpID;
			case E_CDItem.gainWay: return this.gainWay;
			case E_CDItem.resolveType: return this.resolveType;
			case E_CDItem.rare: return this.rare;
			case E_CDItem.level: return this.level;
			case E_CDItem.handBookId: return this.handBookId;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDItem.id: this.id = v; break;
			case E_CDItem.order: this.order = v; break;
			case E_CDItem.name: this.name = v; break;
			case E_CDItem.desc: this.desc = v; break;
			case E_CDItem.color: this.color = v; break;
			case E_CDItem.icon: this.icon = v; break;
			case E_CDItem.itemType: this.itemType = v; break;
			case E_CDItem.useLevel: this.useLevel = v; break;
			case E_CDItem.useType: this.useType = v; break;
			case E_CDItem.useValue_1: this.useValue_1 = v; break;
			case E_CDItem.useValue_2: this.useValue_2 = v; break;
			case E_CDItem.btnType: this.btnType = v; break;
			case E_CDItem.maxCount: this.maxCount = v; break;
			case E_CDItem.saleType: this.saleType = v; break;
			case E_CDItem.saleNum: this.saleNum = v; break;
			case E_CDItem.bagType: this.bagType = v; break;
			case E_CDItem.useJumpID: this.useJumpID = v; break;
			case E_CDItem.gainWay: this.gainWay = v; break;
			case E_CDItem.resolveType: this.resolveType = v; break;
			case E_CDItem.rare: this.rare = v; break;
			case E_CDItem.level: this.level = v; break;
			case E_CDItem.handBookId: this.handBookId = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDItem> = new HashMap<number, CDItem>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDItem[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDItem();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].order = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].color = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].itemType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].useLevel = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].useType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].useValue_1 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].useValue_2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].btnType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].maxCount = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].saleType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].saleNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].bagType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].useJumpID = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].gainWay = [];
			const attrArray = list[i].gainWay;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].resolveType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rare = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].level = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].handBookId = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDItem{
		return this.datas ? this.datas.get(id) : null;
	}
}
